<?php

class user {

//Properti

    var $userName;
    var $password;
    var $headRevision;
    var $userNumRows;
    var $userNumFields;

    //Konstruktor
    function user($Where) {
        $select = "SELECT * FROM `user` ";
        $query = $select . $Where;
        $user = mysql_query($query);
        if ($user) {
            $this->userNumRows = mysql_num_rows($user);
            $this->userNumFields = mysql_num_fields($user);
            $user = mysql_fetch_assoc($user);
            $this->userName = $user["username"];
            $this->password = $user["password"];
            $this->headRevision = $user["headRevision"];
        } else {
            $this->userNumRows = 0;
            $this->userNumFields = 0;
        }
    }

    function changeValues($userName, $password, $headrevision) {
        $this->userName = $userName;
        $this->password = $password;
        $this->headRevision = $headrevision;
    }

    function injectUser() {
        $result = mysql_query("INSERT INTO `user` (`username`,
                                                   `password`,
                                                   `headRevision`)
                                     VALUES ('$this->userName',
                                             '$this->password',
                                             '$this->headRevision')
                                    ;");
        return $result;
    }

    function updateUser() {

        $result = mysql_query("UPDATE `user` SET   `username` = '$this->userName',
                                                    `password` = '$this->password',
                                                    `headRevision` = '$this->headRevision'
                             WHERE `username` = '$this->userName'");
        return $result;
    }

    static function removeUser($nameId) {
        $result = mysql_query("DELETE FROM user WHERE username='$nameId'");
        return $result;
    }

    function getUserName() {
        if ($this->userNumRows == 0) {
            return "kosong gan";
        }
        return $this->userName;
    }

    function getPassword() {
        if ($this->userNumRows == 0) {
            return "kosong gan";
        }
        return $this->password;
    }

    function getHeadRevision() {
        if ($this->userNumRows == 0) {
            return "kosong gan";
        }
        return $this->headRevision;
    }

    function getUserNumRows() {
        return $this->userNumRows;
    }

    function getUserNumFields() {
        if ($this->userNumRows == 0) {
            return "kosong gan";
        }
        return $this->userNumFields;
    }

}

?>
